package org.sage.sdk.dada.order.service;

import lombok.Setter;
import org.sage.sdk.dada.infrastructure.common.response.BaseResponse;
import org.sage.sdk.dada.infrastructure.common.response.result.*;
import org.sage.sdk.dada.infrastructure.dada.openapi.java.client.DadaRequestClient;
import org.sage.sdk.dada.infrastructure.dada.openapi.java.config.AppConfig;
import org.sage.sdk.dada.infrastructure.dada.openapi.java.utils.JSONUtil;
import org.sage.sdk.dada.order.entity.*;

/**
 * @author 周广明
 * @version v1 2019/12/11 下午4:06
 */
public class DadaOrderManager implements IDadaOrderManager {

    @Setter
    AppConfig appConfig;

    @Override
    public BaseResponse<QueryOrderDetailsResult> queryOrderDetails(QueryOrderDetails model) {
        // 请求
        BaseResponse<QueryOrderDetailsResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        QueryOrderDetailsResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), QueryOrderDetailsResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<AdditionalOrdersResult> additionalOrders(AdditionalOrders model) {
        // 请求
        BaseResponse<AdditionalOrdersResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        AdditionalOrdersResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), AdditionalOrdersResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<AddOrderResult> addOrder(AddOrder model) {
        // 请求
        BaseResponse<AddOrderResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        AddOrderResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), AddOrderResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<AddTipResult> addTip(AddTip model) {
        // 请求
        BaseResponse<AddTipResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        AddTipResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), AddTipResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<CancelAdditionalOrderResult> cancelAdditionalOrder(CancelAdditionalOrder model) {
        // 请求
        BaseResponse<CancelAdditionalOrderResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        CancelAdditionalOrderResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), CancelAdditionalOrderResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<CancelOrderResult> cancelOrder(CancelOrder model) {
        // 请求
        BaseResponse<CancelOrderResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        CancelOrderResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), CancelOrderResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<CompleteTheReturnOfAbnormalItemsResult> completeTheReturnOfAbnormalItems(CompleteTheReturnOfAbnormalItems model) {
        // 请求
        BaseResponse<CompleteTheReturnOfAbnormalItemsResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        CompleteTheReturnOfAbnormalItemsResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), CompleteTheReturnOfAbnormalItemsResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<OrderPreReleaseResult> qrderPreRelease(OrderPreRelease model) {
        // 请求
        BaseResponse<OrderPreReleaseResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        OrderPreReleaseResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), OrderPreReleaseResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<QueryAdditionalDistributorResult> queryAdditionalDistributor(BusinessComplaintDada model) {
        // 请求
        BaseResponse<QueryAdditionalDistributorResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        QueryAdditionalDistributorResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), QueryAdditionalDistributorResult.class);

        return baseResponse.data(data);
    }

    @Override
    public BaseResponse<ReAddOrderResult> reAddOrder(ReAddOrder model) {
        // 请求
        BaseResponse<ReAddOrderResult> baseResponse = DadaRequestClient.callRpc(appConfig, model);
        // 获取,转换结果
        ReAddOrderResult data = JSONUtil.fromJson(baseResponse.getResult().toJSONString(), ReAddOrderResult.class);

        return baseResponse.data(data);
    }
}
